package com.wtwd.device.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtwd.device.dao.AppDeviceStepInfoMapper;
import com.wtwd.device.model.entity.DeviceStepInfo;
import com.wtwd.device.service.IDeviceStepInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 每日步数 服务实现类
 * </p>
 *
 * @author mjy
 * @since 2024-05-25
 */
@Service
public class DeviceStepInfoServiceImpl extends ServiceImpl<AppDeviceStepInfoMapper, DeviceStepInfo> implements IDeviceStepInfoService {

    @Resource
    private AppDeviceStepInfoMapper appDeviceStepInfoMapper;

    @Override
    public List<DeviceStepInfo> etDayStepInfoByStartTimeAndEndTime(Long deviceId, Long id, Long startTime, Long endTime) {
        return new LambdaQueryChainWrapper<>(appDeviceStepInfoMapper)
                .eq(DeviceStepInfo::getDeviceId, deviceId)
                .between(DeviceStepInfo::getTime, startTime, endTime)
                .gt(id != null, DeviceStepInfo::getId, id)
                .list();
    }

    @Override
    public DeviceStepInfo getLastDeviceStepInfoByDeviceId(Long deviceId) {
        return appDeviceStepInfoMapper.getLastDeviceStepInfoByDeviceId(deviceId);
    }

    @Override
    public List<DeviceStepInfo> getDayStepInfoByTotalIdGtId(Long totalId, Long id) {
        return new LambdaQueryChainWrapper<>(appDeviceStepInfoMapper)
                .eq(DeviceStepInfo::getDeviceStepId, totalId)
                .gt(id != null, DeviceStepInfo::getId, id)
                .list();
    }

    @Override
    public DeviceStepInfo getLastDeviceStepInfoByTotalId(Long totalId) {
        return appDeviceStepInfoMapper.getLastDeviceStepInfoByTotalId(totalId);
    }

}
